<template>
  <div class="animation">
    <div class="list">
      <div class="item" v-for="item in animationList" :key="item.id" @click="playAnimation(item.id)">
        <div class="img">
          <img :src="item.img" alt="" />
        </div>
        <div class="text">{{ item.name }}</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
const animationList = ref<{ name: string; id: number; img: string }[]>([])

const playAnimation = (id: number) => {
  fdapi.camera.playAnimation(id)
}

onMounted(async () => {
  const { data } = await fdapi.camera.getAnimationList()
  data.forEach(async (item: { id: number; name: string }) => {
    const obj = {
      id: item.id,
      name: item.name,
      img: ''
    }
    const { image } = await fdapi.camera.getAnimationImage(item.name)
    obj.img = 'data:image/png;base64,' + image
    animationList.value.push(obj)
  })
})
</script>

<style lang="scss" scoped>
.animation {
  position: fixed;
  z-index: 9;
  @include Top(120);
  @include Right(40);
  @include Width(220);
  @include hHeight(900);
  background: #428a9722;
  border-radius: 10px;
  .list {
    width: 100%;
    @include Padding(15, 0, 15, 0);
    @include hHeight(900);
    overflow-y: auto;
    .item {
      @include MarginBottom(20);
      @include Padding(0, 10, 0, 10);
      cursor: pointer;
      overflow: hidden;
      position: relative;
      &:hover {
        img {
          transform: scale(1.1);
        }
      }
      .img {
        width: 100%;
        overflow: hidden;
        border-radius: 8px;
        img {
          width: 100%;
          border-radius: 8px;
          transition: all 0.2s;
        }
      }
      .text {
        position: absolute;
        @include Bottom(10);
        width: calc(100% - 10px);
        text-align: center;
        text-shadow: 1px 1px 3px #000000;
      }
    }
  }
}
</style>
